<template>
	<view class="container">
		<view class="print">
			<view class="printname">SunmiPrint<text class="green" v-if="IsConn">（已连接）</text><text class="red" v-else>（连接中...）</text></view>
		</view>
		<view class="square">
			<view class="title">{{ComName}}</view>
			<view class="title">责令（限期）改正通知书</view>
			<view class="subtitle">{{Info.DocNum}}</view>
			<view class="line">{{Info.RealName}}：</view>
			<view class="line indent" v-if="EasyZeGai1!=''">{{EasyZeGai1}}</view>
			<view class="line indent" v-if="EasyZeGai2!=''">{{EasyZeGai2}}</view>
			<view class="line indent" v-if="EasyZeGai3!=''">{{EasyZeGai3}}</view>
			<view class="line indent">行政机关联系人: {{Info.OfficeRealName}}</view>
			<view class="line indent" style="margin-top:-5rpx;">行政机关电话: {{Info.OfficeMobile}}</view>
			<view class="line indent" style="margin-top:-5rpx;">行政机关地址: {{Info.OfficeAddress}}</view>
			<view class="line indent">当事人签名: </view>
			<view class="line"><image class="signname" :src="Tools.GetImg(Info.SignName,500)" mode="aspectFit"></image> </view>
			<view class="line" style="text-align: right;"><image class="chapter" :src="Chapter"/></view>
			<view class="line" style="text-align: right; padding-right: 40rpx;">{{Info.CreateDate.ToDateTwo()}}</view>
		</view>
		<canvas :style="'width: 100px; height: 40px; position: absolute; left:-1000px; bottom:-1000px;'" canvas-id="signname"></canvas>
		<canvas :style="'width: 90px; height: 90px; position: absolute; left:-1000px; bottom:-1000px;'" canvas-id="chapter"></canvas>
		<view class="btn">
			<button class="publishs" @click="Print" v-if="IsReady && IsConn">打印</button>
			<button class="publishs graybg" v-else>请稍候...</button>
		</view>
	</view>
</template>

<script>
	//#ifdef APP
	const print = uni.requireNativePlugin('Sunmi-Print-Inner')
	//#endif
	export default {
		data() {
			return {
				ID:0,
				Info:{ID:0},
				Contact:{},
				Chapter:'',
				ComName:'',
				EasyZeGai1:'',
				EasyZeGai2:'',
				EasyZeGai3:'',
				IsConn:false,
				IsReady:false,
				SignNameBase64:'',
				ChapterBase64: '',
			};
		},
		onLoad(options) {
			this.ID=options.ID;
			this.Find_EasyInfo();
			print.connect(res => {
				this.IsConn = res.connect == "hello"
			})
		},
		onUnload() {
			print.disconnect();
		},
		methods:{
			Find_EasyInfo(){
				var data = {};
				data.ID=this.ID;
				data.Act="Find_EasyInfo";
				this.Util.Loading("加载中...");
				this.Util.Post(data, json=>{
					this.Util.HideLoading();
					uni.stopPullDownRefresh();
					uni.hideNavigationBarLoading();
					this.Info = json.Data.Info;
					this.Contact = json.Data.Contact;
					this.Chapter = json.Data.Chapter;
					this.ComName=json.Data.ComName;
					this.EasyZeGai1 = json.Data.EasyZeGai1;
					this.EasyZeGai2 = json.Data.EasyZeGai2;
					this.EasyZeGai3 = json.Data.EasyZeGai3;
					this.Util.InitImg_Easy_Sunmi("signname", 100, 40, this.Info.SignName.GetImg(500),() => {
						this.Util.GetBase64("signname", 100, 40, data=>{
							this.SignNameBase64 = data;
						});
					});
					this.Util.InitImg_Easy_Sunmi("chapter", 90, 90 , this.Chapter,() => {
						this.Util.GetBase64("chapter", 90, 90 , data=>{
							this.IsReady = true;
							this.ChapterBase64 = data;
						});
					});
				});
			},
			Print(){
				if(this.Base64=="" || !this.IsConn){
					this.Util.Toast("打印机尚未就绪，请稍后再试！");
					return;
				}
				this.Util.Loading("打印中...");
				print.printText({text:this.ComName,align:1,size:32, bold:true});
				print.printText({text:"责令（限期）改正通知书",align:1,size:25, bold:true});
				print.printText({text:this.Info.DocNum,align:1,size:24, bold:true});
				print.printDividingline({style:"4",height:"30"}); //换行
				print.printText({text:this.Info.RealName+":",align:0,size:24, bold:true});
				if(this.EasyZeGai1!=""){
					print.printText({text:"    "+this.EasyZeGai1,align:0,size:24, bold:true});
					print.printDividingline({style:"4",height:"10"}); //换行
				}
				if(this.EasyZeGai2!=""){
					print.printText({text:"    "+this.EasyZeGai2,align:0,size:24, bold:true});
					print.printDividingline({style:"4",height:"10"}); //换行
				}
				if(this.EasyZeGai3!=""){
					print.printText({text:"    "+this.EasyZeGai3,align:0,size:24, bold:true});
					print.printDividingline({style:"4",height:"10"}); //换行
				}
				print.printDividingline({style:"4",height:"20"}); //换行
				print.printText({text:"    行政机关联系人: " + this.Info.OfficeRealName,align:0,size:24, bold:true});
				print.printText({text:"    行政机关电话: " + this.Info.OfficeMobile,align:0,size:24, bold:true});
				print.printText({text:"    行政机关地址: " + this.Info.OfficeAddress,align:0,size:24, bold:true});
				print.printDividingline({style:"4",height:"20"}); //换行
				print.printText({text:"    当事人签名：" ,align:0,size:24, bold:true});
				if(this.Info.SignName==""){
					print.printDividingline({style:"4",height:"60"}); //换行
				}else{
					print.printBitmap({base64:this.SignNameBase64,align:1});
				}
				print.printDividingline({style:"4",height:"10"}); //换行
				print.printBitmap({base64:this.ChapterBase64,align:2});
				print.printText({text:this.Info.CreateDate.ToDateTwo()+"  ",align:2,size:24, bold:true});
				print.printDividingline({style:"4",height:"60"}); //换行
				print.printDividingline({style:"4",height:"60"}); //换行
				this.Util.HideLoading();
			}
		}
	}
</script>

<style lang="scss">
	.container{width:100%; padding-top:30rpx; padding-bottom:140rpx;
		.print{width:100%; height:90rpx; line-height: 80rpx; font-size:32rpx; padding-left:3%; display: flex; flex-direction: row;
			.printname{flex:1;}
			.printbtn{width:150rpx;}
		}
		.square{width:94%; margin-left:3%; height:auto; border-radius: 10rpx; background-color: #ffffff; padding:40rpx; 
			.title{width:100%; height:70rpx; line-height: 70rpx; font-size:40rpx; text-align: center;}
			.subtitle{width:100%; height:60rpx; line-height: 60rpx; font-size:30rpx; text-align: center;}
			.line{width:100%; height:auto; min-height: 50rpx; line-height:50rpx; margin-top:20rpx; font-size:32rpx; color:#696969;
				.chapter{width:240rpx; height:240rpx;}
				.signname{width:300rpx; height:150rpx;}
			}
		}
	}
</style>
